package gui;

/*
 * @Author: Andy Vidkjaer
 */	

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import domain.Behandling;


public class TableBehandlingModel extends AbstractTableModel{
	
		private static final long serialVersionUID = 1L;
		
		
		private String[] columnNames = new String[] {"Navn","Antal del-behandlinger"};
		private ArrayList<Behandling> data;
		
		
		public TableBehandlingModel(List<Behandling> behandlinger){
			this.data = new ArrayList<Behandling>();
			data.addAll(behandlinger);
		}
		
		public void insertRow(String navn){
			data.add(new Behandling(navn));
			this.fireTableDataChanged();
		}
		
		public int getColumnCount() {
	        return columnNames.length;
	    }

		public void setData(List<Behandling> list){
			data.clear();
			data.addAll(list);
			this.fireTableDataChanged();
		}
		public ArrayList<Behandling> getData(){
			return data;
		}
		
	    public int getRowCount() {
	        return data.size();
	    }

	    public String getColumnName(int col) {
	        return columnNames[col];
	    }

	    public Object getValueAt(int row, int col) { 
	    	Object o = null;
	    	if(data.size() > 0){
	    	if(col==0){   	
	    		o=data.get(row).getNavn();
	    	}else if(col==1){
	    		o=data.get(row).getAllDelBehandlinger().size();
	    	}   	
	    	return o;
	    	}else{
	    		return "";
	    	}
	    }

	    public Class getColumnClass(int c) {
	    	Object o = getValueAt(0, c);
	    	if(o == null){
	    		return "".getClass();
	    	} else {
	    		return o.getClass();
	    	}
	    }

	    /*
	     * Don't need to implement this method unless your table's
	     * editable.
	     */
	    public boolean isCellEditable(int row, int col) {        
	        if(col < 2){    
	    	return true;  
	        }else{
	        	return false;
	        }
	        
	    }

	    /*
	     * Don't need to implement this method unless your table's
	     * data can change.
	     */
	    public void setValueAt(Object value, int row, int col) {
	    	if(col==0){   	
	    		data.get(row).setNavn((String)value);
	    	}  	
	        fireTableDataChanged();
	    }

		public Behandling getItem(int row) {
			return data.get(row);
		}

	    
	    
	    
	    
	    
	    
	    
	    

	}

